/**
 * 	题型为多个角色说话时使用 角色说话时发光  与assignmentArtcleSperk不同的是配置文件不同 某些角色不需要说话
 */
export const optionSpeak = {
	data() {
		return {
			speakCurrent: -1 //正在说话的角色
		}
	},
	computed: {
		questionWord() {
			if (this.speakCurrent > -1) {
				return this.assignment.optionArticles[this.speakCurrent].dialogue
			} else {
				return this.assignment.questionName
			}
		}
	},
	methods: {
		/**
		 * 	播放问题前轮询播放角色对话
		 *  将问题转换成音频播放
		 * 	改变播放状态
		 */
		questionPlay: async function() {
			this.speakCurrent = -1
			setTimeout(() => {
				this.articlePlay()
			}, 1000)
		},
		articlePlay: async function() {
			this.speakCurrent++
			const [text, speaker] = [this.assignment.optionArticles[this.speakCurrent].dialogue, this.assignment.optionArticles[this.speakCurrent]
					.speaker]
			const data = await this.parseTextAudio({
				text: text,
				speaker: speaker
			})
			this.dialogueAudio({
				src: data,
				start: () => {
					this.questionPress = true
				},
				end: () => {
					if (this.speakCurrent === this.assignment.optionArticles.length - 1) {
						this.speakCurrent = -1
						this.qusetionAudio()
						return
					} else {
						setTimeout(() => {
							this.articlePlay()
						}, 1000)
					}
				}
			})
		},
		/**
		 * 	问题播放
		 */
		qusetionAudio: async function() {
			const data = await this.parseTextAudio({
				text: this.assignment.questionName,
				speaker: this.assignment.audioSpeaker ? this.assignment.audioSpeaker : null
			})
			this.dialogueAudio({
				src: data,
				end: () => {
					this.questionPress = false
				}
			})
		},
		/**
		 * 	暂停问题播放
		 */
		questionPause: function() {
			this.dialogueAudio({
				play: false
			})
			this.questionPress = false
			this.speakCurrent = -1
		},
	}
}
